let oldPWdFlag = 0;
let newPWdFlag = 0;
let confirmPWdFlag = 0;

const oldPwdEye = document.querySelector(".showOldPwd");
const newPwdEye = document.querySelector(".showNewPwd");
const confirmPwdEye = document.querySelector(".showConfirmPwd");

let oldPWdInput = document.querySelector("#oldPwd");
let newPWdInput = document.querySelector("#newPwd");
let confirmPWdInput = document.querySelector("#pswdConfirm");

oldPwdEye.onclick = function () {
    if (oldPWdFlag == 0) {
        oldPWdInput.type = "text";
        oldPwdEye.innerHTML = "&#xe715;";
        oldPWdFlag = 1;
    } else {
        oldPWdInput.type = "password";
        oldPwdEye.innerHTML = "&#xe714;";
        oldPWdFlag = 0;
    }
};
newPwdEye.onclick = function () {
    if (newPWdFlag == 0) {
        newPWdInput.type = "text";
        newPwdEye.innerHTML = "&#xe715;";
        newPWdFlag = 1;
    } else {
        newPWdInput.type = "password";
        newPwdEye.innerHTML = "&#xe714;";
        newPWdFlag = 0;
    }
};
confirmPwdEye.onclick = function () {
    if (confirmPWdFlag == 0) {
        confirmPWdInput.type = "text";
        confirmPwdEye.innerHTML = "&#xe715;";
        confirmPWdFlag = 1;
    } else {
        confirmPWdInput.type = "password";
        confirmPwdEye.innerHTML = "&#xe714;";
        confirmPWdFlag = 0;
    }
};

const pswdChangeForm = document.querySelector(".pswdChangeForm");
const pwdReg=/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$/

pswdChangeForm.addEventListener('submit',function (e){
    e.preventDefault()
    let newPwdValue=setText(pswdChangeForm.newPwd.value)
    let confirmPwdValue=setText(document.querySelector('#pswdConfirm').value)

    if(!(newPwdValue==confirmPwdValue)){
        showCustomAlert('两次输入的密码不一致!',false)
        confirmPWdInput.classList.add('warning')
        newPWdInput.classList.add('warning')
    }else if(!pwdReg.test(newPwdValue)){
        showCustomAlert('密码应为8-16位，包含大小写字母和数字!',false)
        newPWdInput.classList.add('warning')
    }else{
        pswdChangeForm.submit()
    }
})